<template>
  <div id="app" v-if="isLogged">
    <el-container>
    <el-header>
      <div class="logo">高校教学资源共享平台</div>
      <div class="header-right">用户信息</div>
    </el-header>
    <el-container>
      <el-aside :style="spread">
        <!-- <el-radio-group v-model="isCollapse" style="margin-bottom: 0px;" @change="spreadChange">
          <el-radio-button :label="false">展开</el-radio-button>
          <el-radio-button :label="true">收起</el-radio-button>
        </el-radio-group> -->
        <div v-if="!isCollapse" class="spreadBtn" @click="spreadChange"><i class="el-icon-d-arrow-left"></i></div>
        <div v-else class="spreadBtn" @click="spreadChange"><i class="el-icon-d-arrow-right"></i></div>
        <!-- <el-button v-if="!isCollapse" type="info" icon="el-icon-caret-left" @click="spreadChange" style="width:100%;"></el-button>
        <el-button v-else type="info" icon="el-icon-caret-right" @click="spreadChange" style="width:100%;"></el-button> -->
        <el-menu 
          :router="true"
          default-active="$route.path"
          class="el-menu-vertical-demo" 
          background-color="#212C32"
          text-color="#fff"
          active-text-color="#C48E68"
          :collapse="isCollapse">
          <el-menu-item index="/">
            <i class="el-icon-location"></i>
            <span slot="title">系统概况</span>
          </el-menu-item>
          <el-submenu index="2">
            <template slot="title">
              <i class="el-icon-menu"></i>
              <span slot="title">数据维护</span>
            </template>

            <el-menu-item-group>
              <!-- <span slot="title">分组一</span> -->
              <el-menu-item index="/users">用户管理</el-menu-item>
              <el-menu-item index="/course">课程管理</el-menu-item>
              <!-- <el-menu-item index="2-3"><router-link to="/classify">分类管理</router-link></el-menu-item> -->
              <el-menu-item index="/classify">分类管理</el-menu-item>
            </el-menu-item-group>
          </el-submenu>
          <!-- <el-menu-item index="3" disabled> -->
          <el-menu-item index="3">
            <i class="el-icon-document"></i>
            <span slot="title">基础设置</span>
          </el-menu-item>
          <el-menu-item index="4">
            <i class="el-icon-setting"></i>
            <span slot="title">系统管理</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-container>
        <el-main>
          <div class="main">
            <div class="navi-bar">
              {{ func_model }}
              <el-button type="info" icon="el-icon-circle-plus-outline" size="mini" @click="spreadChange" style="margin-left: 20px;">添加</el-button>
              <el-button type="info" icon="el-icon-refresh" size="mini" @click="spreadChange">刷新</el-button>
            </div>
            <router-view class="view"/>
          </div>
        </el-main>
      </el-container>
    </el-container>
  </el-container>
  </div>

  <div v-else id="app">
    <router-view class="view"/>
  </div>
</template>

<script>
export default {
  name: "App",
  data () {
    return {
      loggedin: false,
      isCollapse: false,
      func_model: '用户管理',
      spread: {
        width: '300px',
      }
    }
  },
  computed: {
    isLogged() {
      return this.$store.state.loggedin
    }
  },
  methods: {
    spreadChange: function () {
      if (this.isCollapse == true) {
        this.spread.width = '300px'
        this.isCollapse = false
      } else {
        this.spread.width = '64px'
        this.isCollapse = true
      }
    }
  },
  created () {
    // console.log(window.location.href)
    // if (this.loggedin === false & window.location.href !== '/login') {
    //   window.location.href='/login' 
    // }
    // this.refresh = true
  },
  mounted () {
    if (this.loggedin === false && !window.location.href.endsWith('/login')) {
      // window.location.href='/login' 
      this.$router.push('/login')
    }
  }
};
</script>

<style>
#app {
  font-family: "Avenir", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  /*margin-top: 60px;*/
  height: 100%;
}
#app view {
  position: absolute;
  /* top: 50px; */
  /* bottom: 0px; */
  /* right: 0px; */
}

a {
  text-decoration: none;
  color: white;
}
.router-link-active {
  color: #C48E68;
}
.el-menu-itme a:link {
  color: white;
}

/* =================== 菜单栏 ===================== */
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 100%;
  /* min-height: 400px; */
}
/* =============================================== */

.el-container,
.main {
  height: 100%;
}

.el-header {
  background-color: rgb(4, 78, 83);
  color: #333;
  text-align: center;
  line-height: 60px;
}
.el-header .logo {
  width: 260px;
  height: 40px;
  color: white;
  font-size: 24px;
  /* margin: auto 0; */
}
.el-header .header-right {
  position: absolute;
  right: 0;
  top: 0;
  margin-right: 20px;
  color: white;
  height: 60px;
  line-height: 60px;
}

.el-aside {
  background-color: rgb(16, 32, 51);
  color: #333;
  text-align: center;
  /* line-height: 200px; */
}
.el-aside ul {
  border: 0;
}
.el-aside .spreadBtn {
  width: 100%;
  color: white;
  height: 40px;
  line-height: 40px;
  background-color: black;
}

.el-main {
  overflow: hidden;
  color: #333;
  background-color: #ECF0F5;
  text-align: center;
  /* line-height: 160px; */
  padding: 0;
}

.el-main .navi-bar {
  width: 100%;
  height: 38px;
  line-height: 38px;
  text-align: left;
  padding-left: 15px;
  font-size: 16px;
  font-weight: bold;
  background-color: #F5F5F5;
  border-top: 1px solid gray;
  border-bottom: 1px solid gray;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
</style>
